package com.example.serviceconsumer.fallback;

import com.example.serviceconsumer.client.ProductClientB;
import com.example.serviceconsumer.model.Product;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

@Component
public class ProductClientBFallback implements ProductClientB {

    @Override
    public ResponseEntity<Product> getProductById(Long id) {
        System.err.println("断路器B触发: getProductById服务降级响应 - 失败率阈值50%或慢调用阈值30% (>2秒)");
        return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
                .body(new Product(id, "断路器B降级: 查询失败或超时", 0.0));
    }

    @Override
    public ResponseEntity<Product> updateProduct(Long id, Product product) {
        System.err.println("断路器B触发: updateProduct服务降级响应 - 失败率阈值50%或慢调用阈值30% (>2秒)");
        return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
                .body(new Product(id, "断路器B降级: 更新失败或超时", product != null ? product.getPrice() : 0.0));
    }
}